﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Quartz;
using RegulatoryPlatform.DB;
using RegulatoryPlatform.Models;
using RegulatoryPlatform.Tools;

namespace RegulatoryPlatform.ScheduleTask
{
    public abstract class Base : IJob
    {
        /// <summary>
        /// 医疗机构代码
        /// </summary>
        public string YLJGDM = ConfigurationManager.AppSettings["YLJGDM"].ToString();
        /// <summary>
        /// 卫生机构代码
        /// </summary>
        public string WSJGDM = ConfigurationManager.AppSettings["WSJGDM"].ToString();
        public string appId = ConfigurationManager.AppSettings["AppId"].ToString();
        public string publicKey = ConfigurationManager.AppSettings["PublicKey"].ToString();
        public string privateKey = ConfigurationManager.AppSettings["PrivateKey"].ToString();

        /// <summary>
        /// 前置机监管平台数据库
        /// </summary>
        public WGK_RegulatoryEntities db = null;

        /// <summary>
        /// 互联网医院数据库
        /// </summary>
        public WGK_ServiceDataEntities hlwDB = null;

        public RDData rDData = null;

        public Base()
        {
            rDData = new RDData(appId, publicKey, privateKey);
            db = new WGK_RegulatoryEntities();
            hlwDB = new WGK_ServiceDataEntities();
        }

        public abstract Task Execute(IJobExecutionContext context);


        public Response<T> Serialize<T>(string json)
        {
            Response<T> response = JsonConvert.DeserializeObject<Response<T>>(json);
            return response;
        }

        public Response<DeptList> GetDocList(string department = "")
        {
            var json = rDData.GetDataByMethod("Address_Get_Doctor_List", new DocListRequest
            {
                department = department
            });
            return Serialize<DeptList>(json);
        }
    }
    public class Response<T>
    {
        public string sign { get; set; }

        public int status { get; set; }

        public string msg { get; set; }

        public IList<T> content { get; set; }
    }
    public class DocListRequest
    {
        public string department { get; set; }
    }
}
